#include "nodevicepage.h"
#include "defaultgetset.h"
NoDevicePage::NoDevicePage(QWidget *parent) :
    QWidget(parent)
{
    gsettingItem = new DefaultGetSet;
    iconContainer = new QWidget;
    iconLabel = new QLabel(this);
    iconHLayout = new QHBoxLayout;
    iconHLayout->addStretch(0);
    iconHLayout->addWidget(iconLabel);
    iconHLayout->addStretch(0);
    iconHLayout->setMargin(0);
    iconContainer->setLayout(iconHLayout);

    titleContainer = new QWidget;
    titleLabel = new QLabel(this);
    titleHLayout = new QHBoxLayout;
    titleHLayout->addStretch(0);
    titleHLayout->addWidget(titleLabel);
    titleHLayout->addStretch(0);
    titleHLayout->setMargin(0);
    titleContainer->setLayout(titleHLayout);

    detailContainer = new QWidget;
    detailLabel = new QLabel(this);
    detailHLayout = new QHBoxLayout;
    detailHLayout->addStretch(0);
    detailHLayout->addWidget(detailLabel);
    detailHLayout->addStretch(0);
    detailHLayout->setMargin(0);
    detailContainer->setLayout(detailHLayout);

    layout = new QVBoxLayout;
    layout->addStretch(10);
    layout->addWidget(iconContainer);
    layout->addWidget(titleContainer);
    layout->addWidget(detailContainer);
    layout->addStretch(10);
    this->setLayout(layout);
#ifdef __V10__
    iconLabel->setPixmap(QPixmap(":/image/camera-disconnected.png"));
#else

#endif
    iconLabel->setProperty("useIconHighlightEffect", 0x8);
    titleLabel->setText(tr("No device were found"));
    detailLabel->setText(tr("Please connect the camera first and app will continuously retrieve avaliable devices for you"));
    QString nowThemeStyle = gsettingItem->getStyleName();
    this->setGeometry(0,0,300,100);
    QPalette pal(this->palette());
    if (nowThemeStyle == "ukui-dark" || nowThemeStyle == "ukui-black"){
        //设置背景色黑色
        pal.setColor(QPalette::Background,Qt::black);
        this->setPalette(pal);
        iconLabel->setPixmap(QPixmap(":/image/illu-camera-dark.png"));
    }
    else{
        //设置背景色灰色
        pal.setColor(QPalette::Background,Qt::white);
        this->setPalette(pal);
        iconLabel->setPixmap(QPixmap(":/image/illu-camera-light.png"));
    }
    this->setAutoFillBackground(true);
    this->setPalette(pal);
    connect(gsettingItem,&DefaultGetSet::sigThemeChange, this,&NoDevicePage::dealSystemGsettingChange);

}
void NoDevicePage::dealSystemGsettingChange(){
    QString themeNow = gsettingItem->getStyleName();
    QPalette pal(this->palette());
    if(themeNow == "ukui-dark" || themeNow == "ukui-black"){
        pal.setColor(QPalette::Background,Qt::black);
        this->setPalette(pal);
        iconLabel->setPixmap(QPixmap(":/image/illu-camera-dark"));
    }
    else{
        pal.setColor(QPalette::Background,Qt::white);
        this->setPalette(pal);
        iconLabel->setPixmap(QPixmap(":/image/illu-camera-light"));
    }
}
void NoDevicePage::setTips(QString str1,QString str2){
    titleLabel->setText(str1);
    detailLabel->setText(str2);
}
NoDevicePage::~NoDevicePage(){
    delete gsettingItem;
    delete iconContainer;
    delete titleContainer;
    delete detailContainer;
}
